'use strict'

const config = require('../config/config.js')

const {cors, parsebody, tofile} = require('titbit-toolkit')

let cr = new cors(config.cors || {
  allow: '*',
  //允许提交空的referer
  allowEmptyReferer: true
})

module.exports = [
  {
    pre: true,
    middleware: cr.mid()
  },

  {
    middleware: new parsebody,
    method: [
      'POST', 'PUT', 'DELETE'
    ]
  },

  {
    //启用toFile中间件，在上传文件的处理中可以使用面向对象风格的调用方式。
    /**
     * 参考文档
     * {@link https://gitee.com/daoio/titbit-toolkit#tofile%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6}
     */
    middleware: new tofile,
    method: [
      'POST', 'PUT'
    ]
  }
]
